<?php

namespace app\api\controller;

use app\api\service\TopUpService;
use app\common\Common;
use think\facade\Request;

/**
 * 充值
 */
class TopUp extends Base
{
    private $service;

    public function __construct(TopUpService $topUpService)
    {
        parent::__construct();
        $this->service = $topUpService;
    }

    /**
     * 获取充值套餐
     * 
     * @dateTime 2022/09/05
     * @author zhixiang0215@126.com
     * @return json
     */
    public function topUpPackage()
    {
        $params = Request::param();
        $data = $this->service->getTopUpPackage($this->token,$params);
        return Common::success($data);
    }

    /**
     * 获取会员套餐
     * 
     * @dateTime 2022/09/05
     * @author zhixiang0215@126.com
     * @return json
     */
    public function memberPackage()
    {
        $data = $this->service->getMemberPackage();
        return Common::success($data);
    }

    // 是否开启iOS支付
    public function isOpenIosPay()
    {
        $params = Request::param();

        try {
            validate(\app\api\validate\Video::class)->scene('ios_pay')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }

        $data = $this->service->getAppletConfig($params['app_id']);
        return Common::success($data);
    }

    // 获取小程序配置
    public function appletConfig()
    {
        $params = Request::param();

        try {
            validate(\app\api\validate\Video::class)->scene('applet_config')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }

        $data = $this->service->getAppletConfig($params['app_id']);
        return Common::success($data);
    }

    // 获取活动从充值
    public function activityPay()
    {
        $params = Request::param();

        try {
            validate(\app\api\validate\Video::class)->scene('activity_pay')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }

        $data = $this->service->getActivityPay($params['app_id']);
        return Common::success($data);
    }
}
